import java.util.Scanner;


public class MarkRank {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int size = Integer.parseInt(scanner.nextLine());
    Record[] records = new Record[size];
    for (int i = 0; i < size; i++) {
      records[i] = new Record();
      records[i].setRecord(scanner.nextLine());
    }
    System.out.print(Record.compareRecords(records));
  }
}


class Record {

  private String name;
  private String course;
  private int mark;

  public void setRecord(String record) {
    String[] array = record.split(" ");
    this.name = array[0];
    this.course = array[1];
    this.mark = Integer.parseInt(array[2]);
  }

  public int getMark() {
    return this.mark;
  }

  public String getSimpleRecord() {
    return this.name + " " + this.course + "\n";
  }

  public static String compareRecords(Record[] records) {
    int max = 0;
    int min = 100;
    int maxIndex = 0;
    int minIndex = 0;

    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < records.length; i++) {
      if (max < records[i].getMark()) {
        max = records[i].getMark();
        maxIndex = i;
      }
      if (min > records[i].getMark()) {
        min = records[i].getMark();
        minIndex = i;
      }
    }

    builder.append(records[maxIndex].getSimpleRecord());
    builder.append(records[minIndex].getSimpleRecord());

    return builder.toString();
  }
}
